<template>
  <el-select
    :value="value"
    placeholder="请选择员工"
    style="width: 50%"
    @input="$emit('input', $event)" 
  >
    <el-option value=""></el-option>
    <el-option
      v-for="user in usersExculedSelf"
      :label="user.username"
      :key="user.username"
      :value="user.username"
    >
    </el-option>
  </el-select>
</template>

<script>
export default {
  props: ["value", "exclude"],
  data() {
    return {
      users: [],
    };
  },
  computed: {
    usersExculedSelf() {
      if (this.exclude) {
        return this.users.filter(
          (item) => item.username !== this.exclude);
      } else {
        return this.users;
      }
    },
  },
  created() {
    this.axios
      .get("/user/userlist")
      .then((resp) => {
        this.users = resp.data;
      })
      .catch(() => {
        this.$message.error("未成功导入用户姓名");
      });
  },
};
</script>

